package com.groupbuying.sysconfig.dto.mini;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;

/**
 * @Description 支付宝小程序数据格式化工具类
 * @Author Davidbieber
 * @Email davidbieber@163.com
 * @Date 2019/10/25 9:59 上午
 */
public class DataFormatForAlipayMini {

    public  static JSONObject create(MiniAlipayInfo miniAlipayInfo){
        JSONObject jsonParams=new JSONObject();
        jsonParams.put("to_user_id",miniAlipayInfo.getToUserId());
        jsonParams.put("form_id",miniAlipayInfo.getFormId());
        jsonParams.put("user_template_id",miniAlipayInfo.getUserTemplateId());
        jsonParams.put("page",miniAlipayInfo.getPage());
        JSONObject dataParams=new JSONObject();
        for (MiniDataInfo datum : miniAlipayInfo.getData()) {
            JSONObject dataTem = new JSONObject();
            dataTem.put("value", datum.getValue());
            dataParams.put(datum.getName(), dataTem);
        }
        jsonParams.put("data",dataParams);
        return jsonParams;
    }
}
